package edu.nf.ch02.common;

import io.minio.MinioClient;
import org.springframework.beans.factory.FactoryBean;

/**
 * @ClassName MinioFactoryBean
 * @Description
 * @Author Kx
 * @Date 2025/9/4 20:28
 * @Version 1.0
 */
public class MinioFactoryBean implements FactoryBean<MinioOptions> {
    private String host; // minio服务器地址
    private String account; // 账号
    private String password; // 密码
    private String bucketName; // 存储桶名称

    public void setHost(String host) {
        this.host = host;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void setBucketName(String bucketName) {
        this.bucketName = bucketName;
    }

    /**
     * @author: kx
     * @date: 2025/9/4 22:48
     * @return java.lang.Class<?>
     * @description: 获取对象类型
    */
    @Override
    public Class<?> getObjectType() {
        return MinioOptions.class;
    }

    /**
     * @author: kx
     * @date: 2025/9/4 22:50
     * @return edu.nf.ch02.common.MinioOptions
     * @description: 初始化MinioClient并纳入IOC容器管理
    */
    @Override
    public MinioOptions getObject() throws Exception {
        // 创建MinioClient对象
        MinioClient client = MinioClient.builder().endpoint(host).credentials(account, password).build();
        // 将MinioClient对象封装成MinioOptions对象并返回
        return new MinioOptions(client, bucketName);
    }
}
